//
//  BaiduAdInterstitialView.m
//  DayDay
//
//  Created by wade on 16/5/20.
//  Copyright © 2016年 wade. All rights reserved.
//

#import "BaiduAdInterstitialView.h"

@implementation BaiduAdInterstitialView
@synthesize interstitialView = _interstitialView;
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];// 先调用父类的initWithFrame方法
    if (self) {
        
        
        self.interstitialView = [[BaiduMobAdInterstitial alloc] init];
        self.interstitialView.delegate = self;
        //把在mssp.baidu.com上创建后获得的代码位id写到这里
        self.interstitialView.AdUnitTag = BaiduMobAdInterstitialID;
        //    self.interstitialView.AdUnitTag  =@"2403634"; //WiFi环境下可出视频. 若无填充则出大图.
        self.interstitialView.interstitialType = BaiduMobAdViewTypeInterstitialOther;
        // 加载全屏插屏. 每次仅加载一个广告的物料,若需多次使用请在下次展示前重新执行load方法
        [self.interstitialView load];
        
    }
    return self;
}

- (NSString *)publisherId
{
    return  PublisherId; //@"your_own_app_id";
}

-(BOOL) enableLocation
{
    //启用location会有一次alert提示,请根据系统进行相关配置
    return NO;
}


/*********************************** 插屏广告 ****************************************/

/**
 *  广告预加载成功
 */
- (void)interstitialSuccessToLoadAd:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialSuccessToLoadAd");
    //    UIAlertView*alv = [[UIAlertView alloc]initWithTitle:@"加载成功" message:@"可以点击显示插屏了" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
    //    [alv show];
    
    if (interstitial.isReady){
        
        _SuccessBlock();
    }
}

/**
 *  广告预加载失败
 */
- (void)interstitialFailToLoadAd:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialFailToLoadAd");
    //    UIAlertView*alv = [[UIAlertView alloc]initWithTitle:@"加载失败" message:@"请重新点击加载插屏" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
    //    [alv show];
}
/**
 *  广告即将展示
 */
- (void)interstitialWillPresentScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialWillPresentScreen");
}

/**
 *  广告展示成功
 */
- (void)interstitialSuccessPresentScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialSuccessPresentScreen");
}

/**
 *  广告展示失败
 */
- (void)interstitialFailPresentScreen:(BaiduMobAdInterstitial *)interstitial withError:(BaiduMobFailReason) reason
{
    NSLog(@"interstitialFailPresentScreen, withError: %d",reason);
}

/**
 *  广告展示结束
 */
- (void)interstitialDidDismissScreen:(BaiduMobAdInterstitial *)interstitial
{
    NSLog(@"interstitialDidDismissScreen");
}
/*********************************** 插屏广告 ****************************************/

@end
